public class ArrayStack<E> implements Stack {


    ArrayMy<E> arrayMy;

    public ArrayStack() {
        arrayMy = new ArrayMy<>();
    }

    public ArrayStack(int capacity) {
        arrayMy = new ArrayMy<>(capacity);
    }

    @Override
    public int getSize() {
        return arrayMy.getSize();
    }

    @Override
    public boolean isEmpty() {
        return arrayMy.isEmpty();
    }

    @Override
    public void push(Object e) {
        arrayMy.addLast((E) e);
    }

    @Override
    public Object pop() {
        return arrayMy.removeLast();
    }

    @Override
    public Object peek() {
        return arrayMy.getLast();
    }

    @Override
    public String toString() {

        StringBuilder res = new StringBuilder();

        res.append("STACK：");
        res.append('[');

        for (int i = 0; i < arrayMy.getSize(); i++) {
            res.append(arrayMy.get(i));

            if (i != arrayMy.getSize() - 1) {
                res.append(",");
            }
        }
        res.append("] top");
        return res.toString();
    }
}
